package com.spoplar.util;

import java.math.BigDecimal;

/**
 * Created by spoplar on 18-1-31.
 */
public class MathUtils {


    /**
     * 两整数除数保留小数
     *
     * @param a
     * @param b
     * @param count
     * @return
     */
    public static double IntDivToDouble(int a, int b, int count) {
        double _a = Double.valueOf(a);
        double _b = Double.valueOf(b);
        return DoubleDivToDouble(_a, _b, count);
    }

    /**
     * 两字符串除保留小数
     *
     * @param a
     * @param b
     * @param count
     * @return
     */
    public static double StringDivToDouble(String a, String b, int count) {
        double _a = Double.valueOf(a);
        double _b = Double.valueOf(b);
        return DoubleDivToDouble(_a, _b, count);
    }

    /**
     * 两double除保留小数
     * @param a
     * @param b
     * @param count
     * @return
     */
    public static double DoubleDivToDouble(double a, double b, int count) {
        return new BigDecimal((double) a / b).setScale(count, BigDecimal.ROUND_HALF_UP).doubleValue();
    }


    /**
     *
     * @param a
     * @param b
     * @param count
     * @return
     */
    public static double StringMulToDouble(String a,String b,int count ){
         double _a = Double.valueOf(a);
         double _b = Double.valueOf(b);
         return DoubleMulToDouble(_a,_b,count);
    }

    /**
     *
     * @param a
     * @param b
     * @param count
     * @return
     */
    public static double DoubleMulToDouble(double a,double b,int count){
        BigDecimal _a = new BigDecimal(Double.toString(a));
        BigDecimal _b = new BigDecimal(Double.toString(b));
        return _a.multiply(_b).setScale(count,BigDecimal.ROUND_HALF_UP).doubleValue();
    }




}
